package health.lm.com.shop.presenter;

import com.vondear.rxtool.RxSPTool;

import java.util.ArrayList;
import java.util.List;

import health.lm.com.component_base.base.mvp.contract.XPresent;
import health.lm.com.data.App;
import health.lm.com.data.AppModel;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.shop.entity.PeopleChainEntity;
import health.lm.com.shop.entity.PeopleChainMultiEntity;
import health.lm.com.shop.fragment.PeopleChainFragment;
import health.lm.com.shop.model.MallModel;

/**
 * Created by Android Studio .
 * Project：hlian health.lm.com.shop.presenter
 * Date：2019/8/15 9:11
 * Introduce：人脉连首页
 */
public class PeopleChainPresenter extends XPresent<PeopleChainFragment> {
    public void getData() {
        MallModel.getInstance().getPeopleChainData(new SimpleCallBack<PeopleChainEntity>() {
            @Override
            public void onSuccess(PeopleChainEntity pPeopleChainEntity) {
                if (hasV()) getV().setNewData(getResource(pPeopleChainEntity));
            }
        });
    }

    private List<PeopleChainMultiEntity> getResource(PeopleChainEntity chainEntity) {
        List<PeopleChainMultiEntity> multiEntityList = new ArrayList<>();
        //轮播图
        PeopleChainMultiEntity multiEntity1 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_BANNER);
        multiEntity1.setBanner(chainEntity.getBanner());
        multiEntityList.add(multiEntity1);
        //顶部四个按钮
        PeopleChainMultiEntity multiEntity2 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_CATEGORY);
        multiEntityList.add(multiEntity2);
        //推荐商会名片
        PeopleChainMultiEntity multiEntity3 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_RECOMMEND_COMPANY);
        multiEntity3.setRecommend(chainEntity.getRecommend());
        multiEntityList.add(multiEntity3);
        //我的商会
        PeopleChainMultiEntity multiEntity4 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_MY_COMPANY);
        multiEntity4.setMy_business(chainEntity.getMy_business());
        multiEntityList.add(multiEntity4);
        if (hasV()) {
            RxSPTool.putString(getV().getContext(), AppModel.my_business_id, chainEntity.getMy_business().getId());
        }
        if (chainEntity.getDiscover().size() > 0) {
            //发掘人脉
            PeopleChainMultiEntity multiEntity5 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_DISCOVER_PEOPLE);
            multiEntity5.setDiscover(chainEntity.getDiscover());
            multiEntityList.add(multiEntity5);
        }
        //商会动态
        PeopleChainMultiEntity multiEntity6 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_COMPANY_DYNAMIC);
        multiEntity6.setDynamic(chainEntity.getDynamic());
        multiEntityList.add(multiEntity6);
        //推荐商会列表
        PeopleChainMultiEntity multiEntity7 = new PeopleChainMultiEntity(PeopleChainMultiEntity.TYPE_RECOMMEND_COMPANY_2);
        multiEntity7.setBusiness_recommend(chainEntity.getBusiness_recommend());
        multiEntityList.add(multiEntity7);

        return multiEntityList;
    }
}
